﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace UIShare
{
    public static class FormPreloader
    {

        public static SynchronizationContext _SyncContext;


        public static void PreloadOnThread(params BasicForm[] forms)
        {
            ThreadPool.QueueUserWorkItem((o) => {
                FormPreloader.Preload((BasicForm[])o);
            }, forms);
        }

        public static void Preload(params BasicForm[] forms)
        {
            foreach (var form in forms)
            {
                if (form.InvokeRequired)
                {
                    _SyncContext.Post((o) =>
                    {
                        
                    }, form);
                }
                else
                {
                    preload(form);
                }
                
            }
        }

        private static void preload(BasicForm form)
        {
            form.Close();
        }

        
    }


}
